#-*- coding:utf-8 -*-
from django.http import HttpResponse, HttpResponseRedirect
from django.core.mail import EmailMessage
from django.conf import settings
from arnagroup.shortcuts import r
#from arnagroup.shortcuts import r


from arnagroup.communication.forms import CommunactionForms
from arnagroup.communication.models import Communication

def communication(request):
    """
    iletisim sayfasi
    """
    cform = CommunactionForms()
    post = request.POST
    message = ""
    if post:
        form = CommunactionForms(post)
        if form.is_valid():
            fistname = post.get("fistname","")
            lastname = post.get("lastname","")
            email = post.get("email","")
            content = post.get("content","")
            msg = u"Gönderen: %s %s \nEmail : %s \nİçerik : %s"%(fistname, lastname, email, content)
            Communication.objects.create(fistname = fistname, lastname = lastname, email = email, content = content)
            email = EmailMessage(u"Yeni İş Geldi", msg, email, [settings.ILETISIM_MAIL])
            message = u"Mesajınız başarı ile gönderilmiştir."
            try:
                email.send()
            except:
                message = u"Mesajı gönderirken bir problemle karşılaşıldı."
    return r("communication.html", {"form": cform, "message": message}, request)
